package com.vercon.common.room.dao;

import androidx.annotation.NonNull;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Transaction;
import androidx.room.Update;

import com.vercon.common.room.entry.AppDataRoomInfo;

import java.util.List;

import io.reactivex.Completable;
import io.reactivex.Maybe;

@Dao
public interface AppDataRoomDao {

    @Transaction
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Completable insert(@NonNull AppDataRoomInfo appDataRoomInfo);

    @Transaction
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(@NonNull List<AppDataRoomInfo> appDataRoomInfo);

    @Transaction
    @Update
    void updateAppDataRoomInfo(@NonNull AppDataRoomInfo appDataRoomInfo);

    @Transaction
    @Delete
    Completable delete(@NonNull List<AppDataRoomInfo> appDataRoomInfo);

    @Transaction
    @Delete
    Completable delete(@NonNull AppDataRoomInfo... appDataRoomInfo);

    @Transaction
    @Delete
    Completable delete(@NonNull AppDataRoomInfo appDataRoomInfo);

    @Query("DELETE FROM appdata_info ")
    Completable deleteAll();

    @Query("DELETE FROM appdata_info WHERE packageName =:packName")
    void deleteByPackName(@NonNull String packName);

    @Query("SELECT * FROM appdata_info")
    Maybe<List<AppDataRoomInfo>> queryAll();

    @Query("SELECT * FROM appdata_info ORDER BY appdata_info.id DESC")
    Maybe<List<AppDataRoomInfo>> queryAllDesc();

    @Query("SELECT * FROM appdata_info WHERE appdata_info.packageName = :packageName")
    Maybe<AppDataRoomInfo> queryByData(String packageName);


}
